package com.run.motion.controller;

import java.util.List;

import com.run.motion.config.IpConfig;
import com.run.motion.entity.GymImages;
import com.run.motion.service.IGymImagesService;
import com.run.motion.util.page.AjaxResult;
import com.run.motion.util.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 健身房图片Controller
 * 
 * @author lyq
 * @date 2022-03-26
 */
@Api(tags = "健身房图片")
@RestController
@RequestMapping("/gym/images")
public class GymImagesController extends BaseController
{
    @Autowired
    private IGymImagesService gymImagesService;

    @Autowired
    private IpConfig ipConfig;

    /**
     * 查询健身房图片列表
     */
    @ApiOperation(value = "查询健身房图片列表")
    @GetMapping("/list")
    public TableDataInfo list(GymImages gymImages)
    {
        startPage();
        List<GymImages> list = gymImagesService.selectGymImagesList(gymImages);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setUrl(ipConfig.getIp()+list.get(i).getUrl());
        }
        return getDataTable(list);
    }



    /**
     * 获取健身房图片详细信息
     */
    @ApiOperation(value = "获取健身房图片详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gymImagesService.selectGymImagesById(id));
    }

    /**
     * 新增健身房图片
     */
    @PostMapping
    public AjaxResult add(@RequestBody GymImages gymImages)
    {
        return toAjax(gymImagesService.insertGymImages(gymImages));
    }

    /**
     * 修改健身房图片
     */
    @PutMapping
    public AjaxResult edit(@RequestBody GymImages gymImages)
    {
        return toAjax(gymImagesService.updateGymImages(gymImages));
    }

    /**
     * 删除健身房图片
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gymImagesService.deleteGymImagesByIds(ids));
    }
}
